package com.zhijian.medical.util.redis;

import com.zhijian.medical.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class AsyncTask  {
    @Autowired
    private RedisKeyExpirationListener redisKeyExpirationListener;
    @Autowired
    private CacheService cacheService;

    @PostConstruct
    public void runSub() {
        Runnable task = () -> {
            System.out.println("异步任务开始执行");
            cacheService.support().psubscribe(redisKeyExpirationListener, "__keyevent@0__:expired");
            System.out.println("异步任务执行完毕");
        };

        Thread thread = new Thread(task);
        thread.start(); // 启动线程
    }
}
